<template>
  <div>
    <!-- 短信登录 -->
    <el-input placeholder="请输入手机号" v-model="phone"> </el-input>
    <el-input placeholder="请输入验证码" v-model="code">
      <template #append>
        <el-button type="primary" @click="getcode">发送验证码</el-button>
      </template>
    </el-input>

    <el-button type="primary" @click="login">登录</el-button>
  </div>
</template>

<script setup>
import { ref,onMounted } from 'vue'
import axios from 'axios'

const phone = ref('')
const code = ref('')
const getcode = () => {
  console.log('发送验证码');
  axios.get(`http://localhost:8000/api/sms/${phone.value}/`)
  .then((result) => {
    console.log(result.data);
    
  }).catch((err) => {
    
  });
}
const login = () => {
  console.log('登录');
  axios.post(`http://localhost:8000/api/login/`,{
    phone:phone.value,
    code:code.value,
  })
  .then((result) => {
    console.log(result.data);
  }).catch((err) => {
  })
}

onMounted(() => {
  getcode()
  login()
  
})


</script>
